#include <cstdio>
#include <set>

const int N = 100005, bit = 20;
bool vis[N];
int cnt, n, m;
int e_cnt, heads[N], dfn[N], idfn[N], f[bit][N];
long long dep[N], dis[N], ans;
std::set<int> set;

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void dfs(int u, int fa) {
  dfn[u] = ++cnt, idfn[cnt] = u;
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa) {
      dep[v] = dep[u] + 1;
      dis[v] = dis[u] + e[i].w;
      f[0][v] = u;
      dfs(v, u);
    }
  }
}

inline int lca(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  for (int i = bit - 1; ~i; --i)
    if (dep[f[i][x]] >= dep[y]) x = f[i][x];
  if (x == y) return x;
  for (int i = bit - 1; ~i; --i)
    if (f[i][x] != f[i][y]) x = f[i][x], y = f[i][y];
  return f[0][x];
}

inline long long getdis(int x, int y) { return dis[x] + dis[y] - (dis[lca(x, y)] << 1); }

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P3320 [SDOI2015]寻宝游戏.in", "r", stdin);
  freopen("P3320 [SDOI2015]寻宝游戏.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1, x, y, z; i < n; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z), add(y, x, z);
  }
  f[0][1] = 1, dep[1] = 1;
  dfs(1, 1);
  for (int i = 1; i < bit; ++i)
    for (int j = 1; j <= n; ++j) f[i][j] = f[i - 1][f[i - 1][j]];
  for (int i = 1, t, y, z; i <= m; ++i) {
    scanf("%d", &t);
    std::set<int>::iterator iter;
    t = dfn[t];
    if (!vis[idfn[t]]) set.insert(t);
    y = idfn[(iter = set.lower_bound(t)) == set.begin() ? *--set.end() : *--iter];
    z = idfn[(iter = set.upper_bound(t)) == set.end() ? *set.begin() : *iter];
    if (vis[idfn[t]]) set.erase(t);
    t = idfn[t];
    long long d = getdis(t, y) + getdis(t, z) - getdis(y, z);
    if (!vis[t])
      vis[t] = true, ans += d;
    else
      vis[t] = false, ans -= d;
    printf("%lld\n", ans);
  }
  return 0;
}